<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/5/11
 * Time: 9:15
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class CommunityAuthorModel
 * @package SDXApi\Model
 */
class CommunityAuthorModel extends Model
{
    /**
     * @var string
     */
    protected $tableName = 'community_author';

    /**
     * Created by Jerry
     * @param null $fieldName
     * @param int $id
     * @param int $number
     * @return bool
     */
    public function setCommunityAuthorInc($fieldName = null, $id = 0, $number = 1)
    {
        if (is_null($fieldName) || empty($id)) {
            return false;
        }

        $where = array(
            'id'    =>  $id,
        );

        return $this->where($where)
                    ->setInc($fieldName, $number);
    }

    /**
     * @author Jerry
     * @param int $author_id
     * @return mixed
     */
    public function findCommunityAuthorByAuthorId($author_id = 0)
    {
        $where = array(
            'id'    =>  $author_id,
        );

        $field = 'id as author_id,title as author,description as author_sub,file_url as head_img,articles as article_count,reading_times';

        return $this->field($field)->where($where)->find();
    }
}